package com.cheung.leetcode.contest.doubleweek.doubleweek133;

import org.junit.jupiter.api.Test;

/**
 * @BelongsProject : java-leetcode
 * @BelongsPackage : com.cheung.leetcode.contest.doubleweek133
 * @Author :  cheungming
 * @CreateTime : 2024-06-30 09:33:14
 * @Description : 第3191题
 * @Version : 1.0
 */
public class Code3191Test {

    public int minOperations(int[] nums) {
        int sum = 0;
        for (int i = 0; i < nums.length - 2; i++) {
            if (nums[i] == 0) {
                sum++;
                nums[i] = 1;
                nums[i + 1] = 1 - nums[i + 1];
                nums[i + 2] = 1 - nums[i + 2];
            }
        }
        if (nums[nums.length - 1] == 0 || nums[nums.length - 2] == 0) {
            return -1;
        }

        return sum;
    }

    @Test
    public void test1() {
        assert minOperations(new int[]{0, 1, 1, 1, 0, 0}) == 3;
    }

    @Test
    public void test2() {
        assert minOperations(new int[]{0, 1, 1, 1}) == -1;
    }

    @Test
    public void test3() {
        assert minOperations(new int[]{1, 0, 0, 1, 1, 0, 1, 1, 1}) == -1;
    }
}
